package com.pinxixi.category.controller;

import com.pinxixi.api.category.CategoryControllerApi;
import com.pinxixi.category.service.CategoryService;
import com.pinxixi.framework.domain.category.Category;
import com.pinxixi.framework.model.response.ListResponseResult;
import com.pinxixi.framework.model.response.QueryResponseResult;
import com.pinxixi.framework.model.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController implements CategoryControllerApi {

    @Autowired
    private CategoryService categoryService;


    @Override
    @GetMapping("/findAll")
    public ListResponseResult<Category> findAll() {
        return categoryService.findAll();
    }

    @Override
    @GetMapping("/findPage/{parentId}")
    public ListResponseResult<Category> findListByPid(@PathVariable("parentId") Long parentId) {
        return categoryService.findListByPid(parentId);
    }

    @Override
    @GetMapping("/findOne/{id}")
    public QueryResponseResult<Category> findOne(@PathVariable("id") Long id) {
        return categoryService.findOne(id);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody Category category) {
        return categoryService.save(category);
    }

    @Override
    @DeleteMapping("/deleteAll")
    public ResponseResult deleteAll(Long[] ids) {
        return categoryService.deleteAll(ids);
    }

    @Override
    @GetMapping("/findByName")
    public QueryResponseResult<Category> findByName(String name) {
        return categoryService.findByName(name);
    }
}
